package com.skit.jetpackstudy.livedata;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

/**
 * Author: shuike,
 * Email: shuike007@126.com,
 * Date: 2019/12/29.
 * PS:
 */
public class ViewModelWithLiveData extends ViewModel {
    private MutableLiveData<Integer> number;
//    ViewModelWithLiveData(){
//
//    }

    public MutableLiveData<Integer> getNumber() {
        if(number == null){
            number = new MutableLiveData<>();
            number.setValue(0);
        }
        return number;
    }

    public void addNumber(int n) {
        if (number == null) return;
        number.setValue(n+number.getValue());
    }
}
